using UnityEngine;

public class BarRotateController : MonoBehaviour
{
        
    [SerializeField] private Camera _camera;

    private Transform _barTransform;

    private void Awake()
    {
        if(_camera == null)
            _camera = Camera.main;
        _barTransform = transform.parent;
    }

    private void OnMouseDown()
    {
        _barTransform.GetComponent<BarController>().SetFinishedDrag(false);
    }

    private void OnMouseDrag()
    {
        Vector3 up = _camera.ScreenToWorldPoint(Input.mousePosition) - _barTransform.position;
        up.z = 0;
        _barTransform.up = up;
    }

    private void OnMouseUp()
    {
        _barTransform.GetComponent<BarController>().SetFinishedDrag(true);
    }

}
